<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML>
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>销售阶段</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	
	<link rel="stylesheet" href="css/vivo.css">
	<link rel="stylesheet" href="css/bootstrap.css">
	<link rel="stylesheet" href="js/bootstrap2/css/bootstrap.min.css">
	<link rel="stylesheet" href="css/common.css">
	<link href="js/select2/select2.min.css" type="text/css" rel="stylesheet" />
	
	<script src="js/jquery-1.11.1.js"></script>
	<script type="text/javascript" src="js/layui-v2.1.5/layui/layui.all.js"></script>
	<script type="text/javascript" src="<%=basePath %>js/My97DatePicker/WdatePicker.js"></script>
	<script src="js/select2/select2.min.js"></script>
	<script type="text/javascript" src="js/form.js"></script>
  </head>
  <script type="text/javascript">
	  $(function(){
		  //初始化销售形式
		    var salesFormS2=$("select[name='salesForm']").select2();
			//如果已经保存过了，则开启只读状态
			<c:if test="${not empty requestScope.marketStage }">
				$("#marketStage").find("input").attr("readonly",true);
				$("#marketStage .Wdate,select").attr("disabled",true);
			</c:if>
			
			//悬浮提示
			toolTip();
			//修改字段标记记录变量
			<c:set var="marks" value="原数据"/>
	  })

  </script>
  <body>
  <div style="padding:0px 10px" id="marketStage">
		<div class="panel panel-default">
			<div class="panel-heading">
      			<h5 class="panel-title">销售阶段</h5>
   			</div>
			<div class="panel-body">
				<table cellpadding="10" cellspacing="5" class="mytable">
					<tr>
						<td width="70">销售时间</td>
						<td width="370"><input name="marketDate" class="Wdate" readonly="readonly" value="<fmt:formatDate value="${requestScope.marketStage.marketDate }" pattern="yyyy-MM-dd" />" onClick="WdatePicker({dateFmt:'yyyy-MM-dd'})"/>
							<c:if test="${not empty requestScope.map.marketDate }"><span class="toolTip mark-msg" data-tip="<fmt:formatDate  value="${requestScope.map.marketDate }" type="both" pattern="yyyy-MM-dd" />">
								<c:out value="${marks}"/></span>
							</c:if>
						</td>
						<td width="70">销售形式</td>
						<td width="230">
							<select name="salesForm" style="width: 160px">
								<option value="${requestScope.marketStage.salesForm }" selected="selected">${requestScope.marketStage.salesForm }</option>
							</select>
							<c:if test="${not empty requestScope.map.salesForm }"><span class="toolTip mark-msg"data-tip="${requestScope.map.salesForm }">
								<c:out value="${marks}"/></span>
							</c:if>
						</td>
						<td width="70">销售案名</td>
						<td><input name="marketName" value="${requestScope.marketStage.marketName }" />
							<c:if test="${not empty requestScope.map.marketName }"><span class="toolTip mark-msg"data-tip="${requestScope.map.marketName }">
								<c:out value="${marks}"/></span>
							</c:if>
						</td>
						
					</tr>
					<tr>
						<td width="70">销售单位</td>
						<td><input name="marketUnit" value="${requestScope.marketStage.marketUnit }" class="input_name toolTip"/>
							<c:if test="${not empty requestScope.map.marketUnit }"><span class="toolTip mark-msg" data-tip="${requestScope.map.marketUnit }">
								<c:out value="${marks}"/></span>
							</c:if>
						</td>
						<td width="70">销售经理</td>
						<td><input  name="marketAssociate" value="${requestScope.marketStage.marketAssociate }" />
							<c:if test="${not empty requestScope.map.marketAssociate }"><span class="toolTip mark-msg"data-tip="${requestScope.map.marketAssociate }">
								<c:out value="${marks}"/></span>
							</c:if>
						</td>
						<td width="70">销售范围</td>
						<td ><input name="marketScope" value="${requestScope.marketStage.marketScope }" class="toolTip" />
							<c:if test="${not empty requestScope.map.marketScope }"><span class="toolTip mark-msg"data-tip="${requestScope.map.marketScope }">
								<c:out value="${marks}"/></span>
							</c:if>
						</td>
					</tr>
				</table>
			</div>
		</div>
		<input type="hidden" id="entityId_id" name="id" value="${requestScope.marketStage.id }"/>
		<input type="hidden" id="apId" name="apId" value="${requestScope.apId }"/>
		<c:if test="${requestScope.notPassExamine}">
			<!-- 修改时添加变更说明 -->
			<div style="margin:10px;" id="changeRemark">
				审批意见<textarea rows="3" name="changeRemark"style="width:70%"></textarea><span style="color:red;">*</span>
			</div>
			<div style="width:100%;text-align:center; padding-top:0px">
				<button class="btn btn-danger radius my-btn"
					onclick="saveMarket(0)" type="button">同意</button>
				<button class="btn btn-default radius"
					onclick="saveMarket(1)" type="button">拒绝</button>
			</div>
		</c:if>
  </div>
  
  <script type="text/javascript">
	  function saveMarket(opt){
			var marketDate=$("input[name='marketDate']").val();
			var marketName=$("input[name='marketName']").val();
			var marketUnit=$("input[name='marketUnit']").val();
			var marketAssociate=$("input[name='marketAssociate']").val();
			var marketScope=$("input[name='marketScope']").val();
			var id=$("#marketStage #entityId_id").val();
			var apId=$("#marketStage #apId").val();
			var changeRemark = $("#marketStage textarea[name='changeRemark']").val();
			var salesForm = $("select[name='salesForm']").val();
			var url="project/approval/disposeMarket";
			var i = layer.load(2);
			if(id!=""){
				if(changeRemark==""){
					layer.alert("审批意见不能为空");
					layer.close(i);
					return null;
				}else{
					jQuery.ajax({
				    type:"post",
				    async:false,
				    url:url,
			        dataType:"json",
			        data:{
			        	id:id,
			       		marketDate:marketDate,
			        	marketName:marketName,
			        	marketUnit:marketUnit,
			        	marketAssociate:marketAssociate,
			        	marketScope:marketScope,
			        	salesForm:salesForm, 
			        	opt:opt,
			        	approvalRemark:changeRemark,
			        	apId:apId
			        },
				    success:function(responseText){
				    	layer.close(i);
				        if(responseText.success){
				        	layer.alert("保存成功！", {
				        		offset:'20%',
				        		shade:[0.1,'#fff']
							}, function() {
								parent.location.reload();
								parent.parent.getPendingCount();
								parent.parent.getPendingPassCount();
								parent.parent.getPendingBackCount();
							});
			  			}else{
			  				alert(responseText.msg, {icon: 7});
			  				layer.closeAll();
			  			}
				    }
					});
				}
			}
		}
  	
  </script>
  </body>
</html>

